var settings = settings ||{};
var pageContext = new PageContext(settings||{});

pageContext.back = function(target){
	var $lis = $("#page-header>ul>li");
	var len = $lis.length ;
	$($lis.get(len-2)).find("a").click();
}

pageContext.addItemAfter = function(result,para){
	pageContext.back();
};
pageContext.updateItemAfter = function(result,para){
	pageContext.back();
};
//***************input tree**********************//
var dialogTreesetting = {
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			//beforeClick: beforeClickSearch,
			onClick: onDialogInputTreeClickSearch
		}
}; 
var dialogtreeSetting = {
		dialog:true
		,onInputTreeBodyDown:onDialogInputTreeBodyDown
}
var pageContextDialogInputTree = new PageContextInputTree(dialogtreeSetting);

function onDialogInputTreeBodyDown(event) {
	var node = $(event.target).closest("li").attr("treenode");
	var node2 = $(event.target).closest("div");
	if (!($(event.target).attr("treehide")=="false" || node=="" || node2.hasClass("menuContent"))) {
		pageContextDialogInputTree.hideMenu();
	}
}
function onDialogInputTreeClickSearch(e, treeId, treeNode) {
	pageContextDialogInputTree.onClickSearch(e, treeId, treeNode);
}

jQuery(function($) {
	 $(document).find("input").each(function(){
		 $(this).attr("autocomplete","off");
	 });
	pageContext.init();
   var layero = $("#applyeditForm");
   layero.find(".inputElem").mailAutoComplete();
	layero.delegate(".password","keyup change",function(e){
	   var value = $(this).val();
	   var targetname = $(this).attr("targetname");
	   var val = "";
	   val = encryptByAes(value,aesKey);
	   $(layero.find("input[name='"+targetname+"']").get(0)).val(val);
   }); 
	layero.delegate(".treeSel","click",function(e){
		pageContextDialogInputTree.showMenu(this)
	}); 
	layero.find(".treeSel").next("a").on("click",function(e){
		pageContextDialogInputTree.clear(this)
	}); 
	layero.find('select[novalid!="true"]').each(function(){
		var novalid = $(this).attr("noconvert");
		if(novalid!="true"){
			layero.find(this).select2({
	            language: "zh-CN",width:"off"})
	            .next("span").removeClass("col-xs-10-select2").addClass("col-xs-10-select2");
		}
	  });
	pageContext.get({},{
		url:window.global.ctx+"/sys/org/query?noPage=1",
		success:function(result,para){
			var data = result.data;
			if(data){
				var tree = layero.find(".ztree");
				tree.attr("id","treeForm"+"ztree");
				pageContextDialogInputTree.initTree(tree, data.list,dialogTreesetting);
			}
		}
	});
}); 
